package com.shixi.shixitraining.shixitraining.ui.tabmine.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.TabhostBaseFragment;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.test.TestCollectEmpolyBean;
import com.shixi.shixitraining.shixitraining.ui.tabmine.adapter.CollectEmploymentAdapter;
import com.shixi.shixitraining.shixitraining.ui.tabmine.entity.JobCollectBean;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.util.UserManager;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.MYCOLLECT;

/**
 * Created by shenyan on 2018/7/26.
 */

public class CollectEmploymentFragment extends TabhostBaseFragment {

    private JobCollectBean.DataBean.ListsBean listsBean;
    private TextView mNodata;

    @Override
    protected int getlayoutId() {
        return R.layout.fragment_collect_employment;
    }

    @Override
    protected void initPager() {
        mNodata = (TextView) mContentView.findViewById(R.id.tv_nodata);

        String token = UserManager.getInstance().getToken();
        String userId = UserManager.getInstance().getUserId();
        String url=MYCOLLECT+"&token="+token+"&userId="+userId+"&type="+1;
        HttpUtil.getInstance().getApiInterface().jobCollect(url).enqueue(new CallbackImple<JobCollectBean>() {
            @Override
            public void onError(Call<JobCollectBean> call, Throwable t) {
                ToastUtil.showShortToast(getContext(),t.getMessage());

            }

            @Override
            public void onSuccess(Call<JobCollectBean> call, JobCollectBean response) {

                if (response.getStatus()==200){
                    if (response.getData()!=null){

                        List<JobCollectBean.DataBean.ListsBean> lists = response.getData().getLists();
                        RecyclerView mRcView = (RecyclerView) mContentView.findViewById(R.id.rcview_collect_employment);
                        LinearLayoutManager manager=new LinearLayoutManager(getContext());
                        manager.setOrientation(LinearLayoutManager.VERTICAL);
                        mRcView.setLayoutManager(manager);

                        CollectEmploymentAdapter  adapter=new CollectEmploymentAdapter(getContext(), lists);
                        mRcView.setAdapter(adapter);

                    }else {
                        ToastUtil.showShortToast(getContext(),response.getMsg());
                    }

                }else {
                    mNodata.setVisibility(View.VISIBLE);
                    ToastUtil.showShortToast(getContext(),"请求数据失败");
                }

            }
        });




        List<TestCollectEmpolyBean>  data=new ArrayList<>();
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));
        data.add(new TestCollectEmpolyBean("美国金融实习岗位-信托和过桥基金业务","金融","美国/纽约","全职","2018.03.03"));



    }
}
